package com.yuyi;

import javax.servlet.MultipartConfigElement;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.yuyi.full.handler.exception.OrgExceptionInterceptor;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;

@SpringBootApplication 
@ServletComponentScan   
@MapperScan("com.yuyi.*.dao")
@EnableTransactionManagement
@EnableAsync
public class EKefuApplication {

    /**
     * 修改spring的json为阿里巴巴的fastjson
     */
    @Bean  
    public HttpMessageConverters fastJsonHttpMessageConverters() {
        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();  
        FastJsonConfig fastJsonConfig = new FastJsonConfig();  
        fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);  //允许值为null的键存在 
        fastConverter.setFastJsonConfig(fastJsonConfig);  
        HttpMessageConverter<?> converter = fastConverter;  
        return new HttpMessageConverters(converter);  
    } 
    
    /**  
     * 文件上传配置  
     * @return  
     */  
    @Bean  
    public MultipartConfigElement multipartConfigElement() {  
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        //单个文件最大  
        factory.setMaxFileSize("102400KB"); //KB,MB  
        /// 设置总上传数据总大小  
        factory.setMaxRequestSize("102400KB");  
        return factory.createMultipartConfig();  
    }  
  
    /**
     * 统一异常处理，，拦截器
     * @return
     */
    @Bean
    public OrgExceptionInterceptor doCatchException(){
        return  new OrgExceptionInterceptor();
    }
   
	public static void main(String[] args) {
		SpringApplication.run(EKefuApplication.class, args);
	}

}
